<template>
    <div>
        <h2>房型列表显示</h2>

        <div>
            房型名称：
            <input type="text" v-model="cc.name">
            大小：
            <input type="text" v-model="cc.a1">-
            <input type="text" v-model="cc.a2">

            <input type="button" value="查询" class="btn btn-info" @click="getShow">
        </div>

        <input type="button" value="新增" class="btn btn-primary" @click="add">

        <table class="table table-bordered">
            <tbody>
                <tr class="bg-primary">
                    <td>房号</td>
                    <td>房型名称</td>
                    <td>大小</td>
                    <td>房型图片</td>
                    <td>状态</td>
                    <td>操作</td>
                </tr>

                <tr v-for="item in aa.list" :key="item.Id">
                    <td>{{item.Code}}</td>
                    <td>{{item.Name}}</td>
                    <td>{{item.Area}}</td>
                    <td>
                        <img :src="item.Photo" height="100" width="100" alt="">
                    </td>
                    <td>{{item.State==0?"投放":"未投放"}}</td>
                    <td>
                        <input type="button" value="删除" class="btn btn-danger" @click="del(item.Id)">
                        <input type="button" value="投放" class="btn btn-info" v-if="item.State==1" @click="upd(item.Id,0)">
                        <input type="button" value="未投放" class="btn btn-primary" v-if="item.State==0" @click="upd(item.Id,1)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from 'vue'
import axios from 'axios';
import {useRouter,useRoute} from 'vue-router'
const router=useRouter();
const route=useRoute();
import moment from 'moment'

//修改状态 
const upd=(id:any,state:any)=>{
    if(confirm('确认修改吗')){
        axios({
        method:'put',
        url:'/api/House/UpdStateAll',
        params:{
            ids:id,
            state:state
        }
    })
    .then(res=>{
        console.log(res);
        if(res.data>0){
            alert('成功');
            getShow();
        }
        else{
            alert('失败');
        }
    })
    .catch(err=>{
        console.log(err);
    })
    }

}

//删除
const del=(id:any)=>{
   if(confirm('确认删除吗')){
    axios({
        method:'delete',
        url:'/api/House/DelHouseALL',
        params:{
            ids:id
        }
    })
    .then(res=>{
        console.log(res);
        if(res.data>0){
            alert('成功');
            getShow();
        }
        else{
            alert('失败');
        }
    })
    .catch(err=>{
        console.log(err);
    })
   }
}

onMounted(()=>{
    getShow();
})

let aa:any=reactive({
    list:[]
})

let cc:any=reactive({
    name:'',
    a1:'',
    a2:'',
})

const getShow=()=>{
    axios({
        method:'get',
        url:'/api/House/ShowHouse',
        params:cc
    })
    .then(res=>{
        console.log(res);
        aa.list=res.data;
    })
    .catch(err=>{
        console.log(err);
    })
}



const add=()=>{
    router.push('/addHouse')
}

</script>

<style scoped>

</style>